﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Expo.Training.DataAccess.Vip;

public partial class Vip_EditLevel : PageBase
{
    private Guid _id;
    private LevelEntity _model;

    protected void Page_Load(object sender, EventArgs e)
    {
        _id = new Guid(Request.QueryString["id"].ToString().Trim());

        _model = VipModule.GetLevel(_id);

        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        this.txtTitle.Text = _model.Title;
        this.txtScore.Text = _model.Score.ToString();

    }

    protected void btn_Edit_Click(object sender, EventArgs e)
    {
        string _title;
        int _score;

        _title = this.txtTitle.Text.Trim();
        _score = int.Parse(this.txtScore.Text.Trim());

        _model.Title = _title;
        _model.Score = _score;
        _model.LevelID = _id;

        try
        {
            if (VipModule.UpdateLevel(_model))
            {
                this.AddEndScript("update succes", "alert('修改等级成功！');location.href='LevelManagement.aspx'");
            }
            else
            {
                this.AddEndScript("error", "alert('修改操作出错，请重试！');");
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}
